

myApp.directive('repeatFinish',function(){
	return {
		link: function(scope,element,attr){
			console.log(scope.$index)
			if(scope.$last == true){
				console.log('ng-repeat执行完毕')
				scope.$eval( attr.repeatFinish )
			}
		}
	}
})
//comm方法
myApp.service("commonUtil",function ($http,$q,requestContext,$location,$window,$state,$cookies,$localStorage,$filter) {
    this.showTip=function (selector,desc){
        $(selector).tips({
            side:3,
            msg:desc,
            bg:'#AE81FF',
            time:2
        });
        $(selector).focus();
    };

//校验类型
    this.imgType=function imgType(fileObj){
        if(!validateImgType(fileObj)){
            this.showTip(":file","请上传图片格式的文件(gif、png、jpg、jpeg)");
            $(":file").val('');
            return false;
        }
        return true;
    };

    this.validateImgType=function (fileObj){
        if(fileObj==undefined){
            return false;
        }
//	var fileType=fileObj.name.substr(fileObj.name.lastIndexOf(".")).toLowerCase();//获得文件后缀名
        var fileType=fileObj.type.substring(fileObj.type.lastIndexOf("/")+1).toLowerCase();
        if(fileType != 'gif' && fileType != 'png' && fileType != 'jpg' && fileType != 'jpeg'||fileObj.value==""){
            return false;
        }
        return true;
    };

    this.validateFileSize=function (fileObj,maxSize){
        if(fileObj==undefined){
            return false;
        }
        var size=fileObj.size;
        if(size>maxSize){
            return false;
        }
        return true;
    };
    /**
     * 向页面添加 加载效果
     * @returns
     */
    this.loading=function (){
        var loading='<div id="loading" style="display:none">'+
            '<div class="model_loading"></div>'+
            '<div class="sk-fading-circle">'+
            '<div class="sk-circle1 sk-circle"></div>'+
            '<div class="sk-circle2 sk-circle"></div>'+
            '<div class="sk-circle3 sk-circle"></div>'+
            '<div class="sk-circle4 sk-circle"></div>'+
            '<div class="sk-circle5 sk-circle"></div>'+
            '<div class="sk-circle6 sk-circle"></div>'+
            '<div class="sk-circle7 sk-circle"></div>'+
            '<div class="sk-circle8 sk-circle"></div>'+
            '<div class="sk-circle9 sk-circle"></div>'+
            '<div class="sk-circle10 sk-circle"></div>'+
            '<div class="sk-circle11 sk-circle"></div>'+
            '<div class="sk-circle12 sk-circle"></div>'+
            '</div>'+
            '</div>';
        $("#view").append(loading);
    };
    /**
     * 展示加载框
     * @returns
     */
    this.showLoading=function (){
        $("#loading").show();
    };
    /**
     * 隐藏加载框
     * @returns
     */
    this.hideLoading=function (){
        $("#loading").hide();
    };
    /**
     * 去指定路由
     * @param url
     */
    this.goToUrl=function(url){
        $location.path(url);
        $window.location.href=$location.absUrl();
    }

    this.addActive=function(selector){
        $(".navbar-collapse li.scroll").removeClass("active");
        $(selector).parent().addClass("active");
    }

    this.openSrefUrl=function(uiSref){
        console.log(uiSref);
        var url=$state.href(uiSref,{basicType:8});
        console.log(url);
        window.open(url);
    }
    
    this.openUrl=function(url){
    	window.open(url);
    }

    this.putCookie=function (key,obj) {
        var Days = 1;
        var exp = new Date();
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        var option={'expires': exp};
        $cookies.put(key,JSON.stringify(obj),option);
    }

    this.getCookie=function (key) {
        var value = $cookies.get(key);
        if(!value){
            return value;
        }
        return JSON.parse(value);
    }
    this.removeCookie=function (key) {
        $cookies.remove(key);
    }
    
//    this.getDateToString=function (date, format) {  
//        if (angular.isDate(date) && angular.isString(format)) {  
//            return $filter('date')(date, format);  
//        }  
//    }
    
    this.getStringToDate = function (string) {  
        if (angular.isString(string)) {
            return new Date(string);  
        }  
    }
    
    this.getDateToString=function (date, format) {  
        return $filter('date')(date, format);  
    }
    
    this.getStringDateTolong = function (string) {  
        if (angular.isString(string)) {
            return new Date(string).getTime();  
        }  
    }
    
    this.substringDate = function (string) {  
//    	if (angular.isString(string)) {
    		return $filter('limitTo')(string,19,0);
//    	}  
    }

});
